package com.example;

import com.example.config.AppConfig;
import com.example.service.OrderService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 主程序类，用于测试AOP功能
 */
public class Main {
    public static void main(String[] args) {
        // 初始化Spring容器
        AnnotationConfigApplicationContext context = 
            new AnnotationConfigApplicationContext(AppConfig.class);
        
        // 获取OrderService实例
        OrderService orderService = context.getBean(OrderService.class);
        
        System.out.println("=== 测试add方法 ===");
        try {
            orderService.add("苹果", 5);
        } catch (Exception e) {
            System.out.println("执行add方法时发生异常: " + e.getMessage());
        }
        
        System.out.println("\n=== 测试delete方法 ===");
        try {
            orderService.delete("香蕉");
        } catch (Exception e) {
            System.out.println("执行delete方法时发生异常: " + e.getMessage());
        }
        
        System.out.println("\n=== 测试find方法 ===");
        try {
            orderService.find("橙子");
        } catch (Exception e) {
            System.out.println("执行find方法时发生异常: " + e.getMessage());
        }
        
        // 关闭容器
        context.close();
    }
}
